package com.hou.servicebase.exceptionhandler;

import com.hou.commonutils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author shkstart
 * @create 2021-10-07-21:42
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    // 指定种类异常调用方法
    @ExceptionHandler(Exception.class)
    // 返回数据
    @ResponseBody
    public R error(Exception e){
        log.error(e.getMessage());
        e.printStackTrace();
        return R.error().message("执行了全局异常处理");
    }

}
